<?php

/**
 * pages actions.
 *
 * @package    practil
 * @subpackage pages
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class pagesActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
public function executeIndex(sfWebRequest $request)
{

      


}

public function executeChangePassword(sfWebRequest $request)
{

    $source  = $request->getParameter('sourceUrl');
    $token   = $request->getParameter('tokenPractil');
    $account = $request->getParameter('emailAccount');

    $source = "http://www.google.com.pe/";
   /* if($token==md5($source)){*/
        if($source!=""){
                 $respuesta = @file_get_contents($source);
                 if($respuesta === FALSE){                     
                     return sfView::ERROR;
                 }else{
                        $this->token_post  = md5($account);
                        $this->account     = $account;
                        $this->destination = $source;
                        return sfView::SUCCESS;
                 }           
        }else{
               return sfView::ERROR;
        }
  /*  }else{
        return sfView::ERROR;
    }
    */
}




public function executeExecuteChangePassword(sfWebRequest $request)
{
    
   $destination          = $request->getParameter('hd-destination');
   $email_account        = $request->getParameter('txt-email-account');
   $password             = $request->getParameter('txt-password');
   $new_password         = $request->getParameter('new-password');
   $new_password_repeat  = $request->getParameter('new-password-repeat');


   if($new_password==$new_password_repeat){
       $criteria = new Criteria();
       $criteria->add(UsuarioPeer::EMAIL,$email_account);
       $usuarioBean = UsuarioPeer::doSelectOne($criteria);
       if(is_object($usuarioBean)){
            if($usuarioBean->getPassword()==md5($password)){
                $usuarioBean->setPassword(md5($new_password_repeat));
                $usuarioBean->save();
                $this->redirect($destination);
            }else{
               return sfView::ERROR;
            }           
       }else{
           return sfView::ERROR;
       }  
   }else{
       return sfView::ERROR;
   }

}


public function executeAccount(sfWebRequest $request){

        //test genenerate token forgetPassword
        $codigo= "esferadigital";
        $codigo = md5($codigo);

        $data = http_build_query(
            array(
                'userId'        => 9,
                'plataformaKey' => 1,
                'tokenSecurity' => $codigo
            )
        );

        $response = @file_get_contents("http://localhost/practil/web/frontend_dev.php/json_servicio_usuario/generateTokenForgetPassword?".$data);

        echo $response;
        return sfView::NONE;
}






}
